package org.lanqiao.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.jasper.tagplugins.jstl.core.ForEach;
import org.lanqiao.entity.Account;
import org.lanqiao.service.AccountService;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/account")
public class accountController {
	@Resource
	private AccountService accountService;
	//显示account_list页面
	@RequestMapping("/showAccountlist")
	public String showServicelist() {
		return "redirect:showAccountlist1.do";
	}
	//显示account_add页面 
	@RequestMapping("/showAccountadd")
	public String showServiceadd() {
		return "account/account_add";
	}
	//显示account_modi页面
	@RequestMapping("/showAccountupdate")
	public String showServiceupdate() {
		return "account/account_modi";
	}
	//显示account_detail页面
	@RequestMapping("/showAccountdetail")
	public String showServicedetail() {
		return "account/account_detail";
	}
	/**
	 * 添加业务
	 * @param account
	 * @param request
	 * @return
	 */
	@RequestMapping("/showAccountadd1")
	public String addAccount(Account account,HttpServletRequest request) {
		boolean resultService = accountService.insertService(account);
		if(!resultService){
		//	request.setAttribute("account", account);
			
			return "account/account_add";
		}else{
			HttpSession session=request.getSession();
		 
		System.out.println(1111);
		return "account/account_list";
		
	  }
    }
	/**
	 * 查询
	 * @param account
	 * @param request
	 * @return
	 */
	@RequestMapping("/showAccountlist1")
	public String queryAccount(HttpServletRequest request) {
		List<Account> resultService = accountService.queryService();
		//将查询的结果放到list集合中
		request.setAttribute("list", resultService);
		return "account/account_list";
		
	}
	/**
	 * 删除账务
	 * @param acid
	 * @param request
	 * @return
	 */
	
	@RequestMapping("/showAccountdelete")
	public String deleteAccount(int acid,HttpServletRequest request) {		
		boolean resultService=accountService.deleteAccount(acid);
		if(!resultService) {
			//删除成功
		}
		return "account/account_list";
		
	}
	/**
	 * 修改业务
	 * @param account
	 * @param request
	 * @return
	 */
	@RequestMapping("/showAccountupdate1")
	public String updateAccount(Account account,HttpServletRequest request){
		boolean resultService=accountService.updateAccount(account);
		/*if(!resultService) {
			//添加失败
		}else {
			//添加成功
		}*/
		return "account/account_list";
		
	}
}